#ifndef UDT_REC_DEF
#define UDT_REC_DEF

#include <fields.h>
#include <passwd.h>

#define UTT_FILE_NAME         "utt.dat"
#define ADT_FILE_NAME         "adt.dat"
/*#define SHIFT_ARRAY_SIZE 10  now in sizes.h*/


/* All total in UTT_REC are Net */
typedef struct TagUTT_REC
{
	short  inNetCount;                       /* Number of tran done: sale = +1, refund = +1, Void = -1, Adj. = +0 */
	long lnNetTotAmt;                      /* NetBase+NetTax+NetTip+NetCB+NetSurcharge */
	long lnNetBaseAmt;                     /* Net(SaleBase + VoidRefundBase - VoidSaleBase - RefundBase) */
	                                       /* for Adjustment:  +(TotalofTranAmt - TipAmt) - (OldTotalofTranAmt - OldTipAmt) */
	long lnNetTaxAmt;                      /* Net(Tax Amount) similar to NetBaseAmt Calc. except no adjustment */
	long lnNetTipAmt;                      /* Net(Tip Amount) similar to NetBaseAmt Calc. */
	                                       /* for Adjustment:  +(TipAmt) - (OldTipAmt) */
	long lnNetCashBack;                    /* Net(SaleCashBack - VoidSaleCashBack)   */
	long lnNetSurcharge;                   /* Net(SaleSurcharge + VoidRefundSurcharge - VoidSaleSurcharge - RefundSurcharge */
	long lnTipSale;                        /* (Base Amount of Transaction that has TipAmount != 0) - refund of (Base Amount of Transaction that has TipAmount != 0) */
	                                       /* for Adjustment: (Sale, in refund need to multiply by -1L */ 	       
	                                       /* if change from Tip to no Tip:  TipSale = -OldBaseAmount */
	                                       /* if change from no Tip to Tip:  TipSale =  BaseAmount */
	                                       /* if change from Tip to Tip:     TipSale =  TotalTransAmount - OldTotalTransAmount */
	                                       /* in VOID Sale   TipSale = -BaseAmt */
	                                       /* in VOID Refund  TipSale = BaseAmt  */
} UTT_REC;

#define SIZE_UTT_REC    sizeof(UTT_REC)

typedef struct TagUTT_KEY
{
    long   inRecNum;
  /* char   chShift; */ /* remove for clerk gw */
    char   szClerkID[CLERK_ID_SIZE + 1];
}UTT_KEY;

#define SIZE_UTT_KEY    sizeof(UTT_KEY)

extern UTT_REC srUTTRec;

typedef struct TagUTT_SKEY 
{   
    int         (*compare_func) ();
    int         inUTTKeyIdx;
    UTT_KEY     uttKey;
} UTT_SKEY;



/* file contains id's for clerks with activity in current batch  bb1 */
typedef struct TagADT
{
	char szClerkId[CLERK_ID_SIZE + 1];     /* Clerk Id */
} ADT_REC;

#define SIZE_ADT_REC    sizeof(ADT_REC)


extern char szTempMsg[MESSAGE_SIZE+1];

void vdGetUTTFileName (char *pchUTTFileName);
int inOpenUTT (DB_FILE *psrDBFPtr, char *pchFName);
int inCloseUTT (DB_FILE *psrDBFPtr);
int inUTTCompareFn (UTT_KEY *psrKey, UTT_SKEY *MatchKey);
int inKeyReadUTT (DB_FILE *psrDBFPtr, UTT_REC *psrRec, UTT_KEY *psrKey, int inKeyIdx, long *plnRecNum);
int inGetKeyUTTRec(DB_FILE *psrDBFPtr, UTT_REC *psrRec, UTT_KEY *psrKey, int inKeyIdx, long lnDBWhat);
int inInsertUDTEntry (char *pchClerkId, char *pchPwd, void *psrUDTRec);
int inDeleteUDTEntry (char *pchClerkId, char *pchPwd);
int  inGetUDTPwd (char *pchClerkId, char *pchPwd);
int  inCheckUDTPwd (char *pchPwd, char *pchClerkId);
int  inCheckUDTClerkId (char *pchClerkId);
int  inGetUDTLogedIn (TRANSACTION_OBJECT *pobTran, char *pchClerkId);
int inResetUDTLogedIn (void);
int inUpdateUDTRecord(char *szClrk, long lnCashTip);
int inUpdateUTTRecord(TRANSACTION_OBJECT *pobTran, char *szClrk, int inCnt,
        long lnBase, long lnTax, long lnTip, long lnCsh, long lnSurcharge, long lnTipSale);
int inSetUTTAmount (TRANSACTION_OBJECT *pobTran);
int inGetUDTTotRecs (void);
int inInitUDTAmounts (void);
int inResetUTT (TRANSACTION_OBJECT *pobtran);
int inResetUTT (TRANSACTION_OBJECT *pobtran);
void vdGetADTFileName (char *pchADTFileName);
int inInsertADTEntry (char *pchClerkId, char *szADTFileName);
int inResetADT(void);
int inGetADTTotRecs (void);
int  inVerifyClerkPwd (char *pchPwd, char *pchClerkId);
int inModifyPassword (char *szClerkID, char *szPassword);
int inValidateClerkPwd(char *szInputPwd);

int	inLoadUDTRec (int inRecNumber);
int	inLoadUDTRecFromStruct (int inRecNumber, void *vdStruct);
int	inSaveUDTRec (int inRecNumber);
int	inSaveUDTRecFromStruct (int inRecNumber,  void *vdStruct);
int	inUpdateUDTRec ( void );
int	inUpdateUDTRecFromStruct (void *vdStruct);
void	vdResetUDTRec ( void );
char* szGetClerkId( void );
char* szGetClerkIdFromStruct(void*vdStruct);
void vdSetClerkId(char* szClerkId);
void vdSetClerkIdFromStruct(char* szClerkId, void*vdStruct);
char* szGetClerkPasswd( void );
char* szGetClerkPasswdFromStruct(void*vdStruct);
void vdSetClerkPasswd(char* szClerkPasswd);
void vdSetClerkPasswdFromStruct(char* szClerkPasswd, void*vdStruct);
int inGetLogedIn( void );
int inGetLogedInFromStruct(void*vdStruct);
void vdSetLogedIn(int inLogedIn);
void vdSetLogedInFromStruct(int inLogedIn, void*vdStruct);
long lnGetCashTip( void );
long lnGetCashTipFromStruct(void*vdStruct);
void vdSetCashTip(long lnCashTip);
void vdSetCashTipFromStruct(long lnCashTip, void*vdStruct);

typedef struct TagUDT_REC
{
char szClerkId[CLERK_ID_SIZE + 1];
char szClerkPasswd[PASSWORD_SIZE + 1];
int inLogedIn;
long lnCashTip;
}UDT_REC;


#define SIZE_UDT_REC		sizeof(UDT_REC)
#define UDT_FILENAME		"UDT.dat"

#endif

